const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            category: [],
            land_crop_record: [],
            natural_resources_management: [],
            childDataForm1: [{}],
            form: {},
            cityValue: [],
            cityValue1: [],
            city: [],
            city1: [],
            personal_information: [],
        };
    },
    mounted() {
        this.getCategory();
        this.getCity();
        this.cityValue = ['230000', '232700', '232723']
        this.changeCity(this.cityValue)
    },
    computed: {
        land_crop_record1() {
            return function(str){
                if (str == '0') {
                    return this.land_crop_record.filter(i=>i.Type == '0' && i.Natural_Resource_Ownership == this.dataForm.Yield_Implementation_Subject) 
                } else if (str == '1') {
                    return this.land_crop_record.filter(i=>i.Type == '0' && i.Natural_Resource_Ownership == this.dataForm.Yield_Implementation_Subject)
                } else if (str == '2') {
                    return this.land_crop_record.filter((i=>i.Type == '1'||i.Type == '2') && i.Natural_Resource_Ownership == this.dataForm.Yield_Implementation_Subject)
                } else if (str == '3') {
                    return this.land_crop_record.filter(i.Natural_Resource_Ownership == this.dataForm.Yield_Implementation_Subject)
                } else {
                    return []
                }
            }
        }
    },
    methods: {
        changeCity1(val) {
            if (val.length > 0) {
                this.dataForm.Town_Number = val[1];
                this.dataForm.Village_Number = val[2];
            } else {
                this.dataForm.Village_Number = '';
            }

        },
        handleChange(val, row) {
            if (val) {
                let obj = this.personal.filter(i => i.ID_Card_Number == val)[0];
                if (obj) {
                    row.Contact_Phone = obj.Contact_Phone;
                }
            }
        },
        changeCity(val) {
            if (val.length > 0) {
                this.dataForm.Province_Number = val[0];
                this.dataForm.City_Number = val[1];
                this.dataForm.County_Nubmer = val[2];
                // $.ajax({
                //     headers: requestHeaders(),
                //     url: `${mh}/clientOperation/getDistrictTree`,
                //     type: "GET",
                //     data: {
                //         DistrictCode: val[2]
                //     },
                //     success: (data) => {
                //         this.city1 = data[0].children;
                //     },
                //     complete: (XMLHttpRequest) => {
                //         requestPretreatment(XMLHttpRequest);
                //     },
                //     dataType: "json",
                // });


                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/permissionsTree/getDistrictTreeByPermissions`,
                    type: "GET",
                    data: {
                        DistrictCode: getCookie('village'),
                    },
                    success: (data) => {
                        this.city1 = data; // 直接使用 this
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }
        },
        getCity() {
            $.ajax({
                url: `${absolutepath()}api/Districtjl.json`,
                method: "get",
                success: (data) => {
                    data.forEach(item => {
                        item.children.forEach(ite => {
                            ite.children.forEach(it => {
                                it.children = undefined
                            })
                        })
                    })
                    this.city = data;
                }
            });
        },
        getCategory() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'yield_report_category',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.category = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    SQLSerialNumber: 'f_land_crop_record',
                    Condition: '',
                    ExtensionCondition: '',
                },
                success: (data) => {
                    this.land_crop_record = data; // 直接使用 this
                }, complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'personal_information ',
                    Condition: "Row_Status='0' and RR_Village_Number in (" + getCookie('village') + ")",
                },
                success: (data) => {
                    this.personal_information = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });

        },
        changeland_crop_record(val, item) {
            // let str = "";
            // if (val == '0') {
            //     land_crop_record
            // } else if (val == '1'){

            // } else if (val == '2'){

            // } else if (val == '3'){

            // }
            // $.ajax({
            //     headers: requestHeaders(),
            //     url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
            //     method: "post",
            //     data: {
            //         SQLSerialNumber: 'f_land_crop_record',
            //         Condition: '',
            //         ExtensionCondition: window.btoa(unescape(encodeURIComponent(str))),
            //     },
            //     success: (data) => {
            //         this.land_crop_record = data; // 直接使用 this
            //     }, complete: (XMLHttpRequest) => {
            //         requestPretreatment(XMLHttpRequest);
            //     },
            //     dataType: "json",
            // });
        },
        changeRecord(val, item, index) {
            if (val) {
                let obj = this.land_crop_record.filter(i => i.Record_SerialNumber == val)[0];
                if (obj) {
                    this.form[index] = obj;
                    item.Natural_Resource_SerialNumber = obj.Land_SerialNumber;
                } else {
                    delete this.form[index];
                    item.Natural_Resource_SerialNumber = '';
                }
            } else {
                delete this.form[index];
                item.Natural_Resource_SerialNumber = '';
            }
        }
    },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-cascader', ylCascader);
app.component('yl-select', ylSelect)
app.component('yl-text-editor', ylTextEditor);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
